package com.seele.tigerwallet.ui.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

@SuppressLint("AppCompatCustomView")
public class GradientTextView extends TextView {


    Typeface font;
    private LinearGradient mLinearGradient;
    private Paint mPaint;
    private int mViewWidth = 0;
    private Rect mTextBound = new Rect();

    public GradientTextView(Context context) {
        super(context);
    }

    public GradientTextView(Context context,
                            AttributeSet attrs) {
        super(context, attrs);
    }

    public GradientTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        font= Typeface.createFromAsset(context.getAssets(), "fonts/CENTURY_GOTHIC_BOLD.TTF");
        setTypeface(font);

    }

    @Override
    protected void onLayout(boolean changed,
                            int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        if (changed) {
//            LinearGradient mLinearGradient = new LinearGradient(0, 0, getWidth(), getHeight(),
//                    new int[]{ 0xffd5ba90, 0xffBB9662},
//                    null, Shader.TileMode.REPEAT);
//
//            setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
//            getPaint().setShader(mLinearGradient);

//



//            getPaint().setShader(new LinearGradient(0, 0, getWidth(), 0, getResources().getColor(R.color.color_CBAC7B), Color.WHITE, Shader.TileMode.CLAMP));
        }
    }


    @Override
    protected void onDraw(Canvas canvas) {
//        0xff030000  0xffcbac7b


                mViewWidth = getMeasuredWidth();
        mPaint = getPaint();
        mLinearGradient = new LinearGradient(0, 0, getWidth(),
                getHeight(), new int[] {  0xffd5ba90, 0xffBB9662}, null, Shader.TileMode.REPEAT);
        mPaint.setShader(mLinearGradient);


//        canvas.drawText(mTipText, getMeasuredWidth() / 2 - mTextBound.width() / 2, getMeasuredHeight() / 2 +   mTextBound.height()/2, mPaint);
//        canvas.drawText(mTipText, getMeasuredWidth() / 2 - mTextBound.width() / 2, getMeasuredHeight() / 2 +   mTextBound.height()/2, mPaint);
//
//        LinearGradient mLinearGradient = new LinearGradient(0, 0,0, 0,
//
//                new int[]{getResources().getColor(R.color.color_CBAC7B), getResources().getColor(R.color.color_030000),  getResources().getColor(R.color.color_FFFFFF)},
//
//                new float[] { 0, 0.5f, 1 }, Shader.TileMode.CLAMP);
//
//        getPaint().setShader(mLinearGradient);





        super.onDraw(canvas);
    }
}
